﻿<UserControl x:Class="TFSArtifactManager.Views.ProjectArtifactsView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:TFSArtifactManager.Plumbing"                          
        xmlns:extToolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
             mc:Ignorable="d"
        x:Name="TheProjectArtifactsView"
        Loaded="TheProjectArtifactsView_Loaded"                     
        DataContext="{Binding ProjectArtifacts, Source={StaticResource Locator}}">
    <UserControl.Resources>
        <local:StringIntValueConverter x:Key="StringIntConverter" />
        <Style x:Key="LabelMargin" TargetType="Label">
            <Setter Property="Margin" Value="10,0,0,0"/>
            <Setter Property="ContentStringFormat" Value="G"/>
            <Style.Triggers>
                <Trigger Property="Content" Value="0">
                    <Setter Property="Visibility" Value="Hidden"/>
                </Trigger>
            </Style.Triggers>
        </Style>        
    </UserControl.Resources>
    <DockPanel LastChildFill="True">
        <extToolkit:BusyIndicator IsBusy="{Binding IsFetching}" DockPanel.Dock="Top" DisplayAfter="0">
            <extToolkit:BusyIndicator.BusyContentTemplate>
                <DataTemplate>
                    <StackPanel MaxWidth="500" Margin="4" DataContext="{Binding DataContext.Progress, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}">
                        <TextBlock Text="{Binding Stage}" FontWeight="Bold" HorizontalAlignment="Center"/>
                        <StackPanel Margin="4">
                            <TextBlock Text="{Binding Message}" TextWrapping="Wrap" Height="30" Width="475" HorizontalAlignment="Left" />
                            <ProgressBar IsIndeterminate="True" Height="15" Margin="0,4,0,4"/>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                <TextBlock Text="{Binding ItemTypeIdBy}"/>
                            </StackPanel>
                            <TextBlock Text="{Binding ItemTitle}" HorizontalAlignment="Left"/>                            
                        </StackPanel>
                        <Grid DataContext="{Binding DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Button Grid.Column="0" Content="Cancel" Command="{Binding CancelDownloadCommand}" HorizontalAlignment="Right" Margin="0 0 2 0"/>
                            
                        </Grid>
                    </StackPanel>
                </DataTemplate>
            </extToolkit:BusyIndicator.BusyContentTemplate>
            <extToolkit:BusyIndicator.OverlayStyle>
                <Style TargetType="Rectangle">
                    <Setter Property="Fill" Value="Transparent"/>
                </Style>
            </extToolkit:BusyIndicator.OverlayStyle>
            <extToolkit:BusyIndicator.ProgressBarStyle>
                <Style TargetType="ProgressBar">
                    <Setter Property="Visibility" Value="Collapsed"/>
                </Style>
            </extToolkit:BusyIndicator.ProgressBarStyle>

            <!-- content: -->
            <StackPanel x:Name="uxControlContainer"  Orientation="Horizontal" VerticalAlignment="Top" Margin="8">

                <StackPanel Orientation="Vertical">                    
                    <StackPanel Orientation="Horizontal">
                        <Label x:Name="uxIdLabel" Content="TFS Root Work Item Id" VerticalAlignment="Top"/>
                        <TextBox x:Name="uxIdTextBox" Width="50" Height="25" AcceptsReturn="False" MaxLength="7" VerticalAlignment="Top" TextWrapping="NoWrap" PreviewTextInput="uxIdTextBox_PreviewTextInput" 
                             Text="{Binding ProjectId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource StringIntConverter}}"
                             ToolTip="Root TFS work item id (i.e. project work item)">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="LostFocus">
                                    <cmd:EventToCommand Command="{Binding CheckWorkItemIdCommand}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </TextBox>
                    </StackPanel>
                    <extToolkit:WatermarkTextBox IsReadOnly="True" Text="{Binding WorkItemTitle}" Background="WhiteSmoke" Margin="3,0,0,3" 
                        Width="177" HorizontalAlignment="Left" Watermark="[Work Item Description]" ToolTip="{Binding WorkItemTitle}"/>
                </StackPanel>

                <TextBlock Text="Source Control Exclusions" Margin="20,0,8,8"/>
                <TextBox x:Name="uxSourceExclusions" Text="{Binding SourceControlExclusionsText}" MaxHeight="125" MinWidth="350" MinHeight="50" TextWrapping="NoWrap" 
                         AcceptsReturn="True" VerticalScrollBarVisibility="Auto" ToolTip="Enter TFS paths, one per line. i.e. $Project/Folder/Subfolder/"/>

                <Button x:Name="uxProjectIdButton" Content="{Binding FetchText}" VerticalAlignment="Top" Height="25" Width="75" Margin="8,0,0,0" 
                        Command="{Binding ProjectArtifactsCommand}" CommandParameter="{Binding ElementName=uxIdTextBox, Path=Text}" IsDefault="True"/>

                <Button x:Name="uxDbPackageButton" Content="DB Package" ToolTip="Database Packager" VerticalAlignment="Top" Height="25" Width="90" Margin="8,0,0,0" 
                        Command="{Binding DbPackageCommand}"/>
            </StackPanel>
        </extToolkit:BusyIndicator>

        <TextBox TextWrapping="NoWrap" VerticalScrollBarVisibility="Auto" IsReadOnly="True" Text="{Binding Log}"/>
    </DockPanel>
</UserControl>
